#ifndef __DETU_MEDIA_VI_DEV_IMP_H__
#define __DETU_MEDIA_VI_DEV_IMP_H__

#include "vi_dev.h"
#include "mutex.h"

#include "hi_common.h"
#include "hi_comm_vi.h"

namespace detu_media
{

class ViMgrImp;

class ViDevImp: public ViDev
{
protected:
	ViDevImp();

	~ViDevImp();

	friend class ViMgrImp;

public:
	virtual S_Result start(void);
	
	virtual S_Result stop(void);
	
	virtual bool isStarted(void);

	virtual S_Result getId(int& id);
	
private:
	S_Result init(const Json::Value& config);
	
	S_Result deinit(void);
	
	bool isInited(void);
	
private:
	
	constexpr static const VI_DEV_ATTR_S defaultDevAttr = 
	{
	    .enIntfMode 				= VI_MODE_MIPI,
	    .enWorkMode 				= VI_WORK_MODE_1Multiplex,
	    .au32ComponentMask 			= {0xFFF00000,    0x0},
	    .enScanMode 				= VI_SCAN_PROGRESSIVE,
	    .as32AdChnId 				= { -1, -1, -1, -1},
	    .enDataSeq 					= VI_DATA_SEQ_YUYV,
	    .stSynCfg 					= 
	    {
	        .enVsync 				= VI_VSYNC_PULSE,
	        .enVsyncNeg 			= VI_VSYNC_NEG_LOW,
	        .enHsync 				= VI_HSYNC_VALID_SINGNAL,
	        .enHsyncNeg 			= VI_HSYNC_NEG_HIGH,
	        .enVsyncValid 			= VI_VSYNC_VALID_SINGAL,
	        .enVsyncValidNeg 		= VI_VSYNC_VALID_NEG_HIGH,
	        .stTimingBlank = 
	        {
	            .u32HsyncHfb 		= 0,
				.u32HsyncAct 		= 1280,
				.u32HsyncHbb 		= 0,
	            .u32VsyncVfb 		= 0,
	            .u32VsyncVact 		= 720,
	            .u32VsyncVbb 		= 0,
	            .u32VsyncVbfb 		= 0,
	            .u32VsyncVbact 		= 0,
	            .u32VsyncVbbb 		= 0
	        }
	    },
	    /* Embeded ISP*/
	    .enInputDataType 			= VI_DATA_TYPE_RGB,
	    .bDataReverse 				= HI_FALSE,
	    .stSize = 
	    {
	    	.u32Width 				= 3968,
			.u32Height 				= 2768
		},
	    .stBasAttr 					= 
	    {
	        .stSacleAttr 			= 
			{
	            .stBasSize 			= 
				{
					.u32Width 		= 3968,
					.u32Height 		= 2768
				}
	        },
	        .stRephaseAttr 			= 
	        {
	            .enHRephaseMode 	= VI_REPHASE_MODE_NONE,
	            .enVRephaseMode 	= VI_REPHASE_MODE_NONE
	        }
	    },
	    .stWDRAttr 					= 
	    {
	        .enWDRMode 				= WDR_MODE_NONE,
	        .u32CacheLine 			= 2768
	    },
	    .enDataRate 				= DATA_RATE_X1
	};

private:
	bool fInited;
	int fRef;
	VI_DEV fDevId;
	VI_DEV_ATTR_S fDevAttr;
	VI_DEV_BIND_PIPE_S fBindPipe;

	detu_infra::Mutex fMutex;
	
};

}

#endif

